package com.lightjet.macross.base.upms.repository;

import com.lightjet.macross.base.upms.domain.SysOrganization;
import com.lightjet.macross.common.core.BaseRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository("sysOrganizationRepository")
public interface SysOrganizationRepository extends BaseRepository<SysOrganization, String> {

    SysOrganization findDistinctById(String id);

    SysOrganization findDistinctByOrgancode(String name);

    @Query("select t from SysOrganization t where t.displayname like :keywords or coalesce(t.organcode,'!@#') like :keywords or t.shortname like :keywords")
    List<SysOrganization> findByKeywords(@Param("keywords") String keywords);

    @Query("select t from SysOrganization t where t.parent is null")
    List<SysOrganization> findRootOrgs();
}
